
package utils;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * Provides facilities  to write into a file
 * As it is solely used for the xml stuff and in order
 * to balance "XMLReader", it has been called XMLWriter
 * but actually it provides only basic operations needed to manipulate
 * a common file   
 * 
 * @author Equipe SimPack 2004
 * @created March 29 2004
 * @modified May 15, 2004
 *
 */

public class XMLWriter  {

	
    private BufferedWriter   _out;
    private String           _fileName;

    /**
     * Constructor myWriter
     * @param nomfichier the name of the file you are going to write into
     */
    public XMLWriter(String fileName){
	_fileName = fileName;
    }	


    public boolean fileExists(){
	File f = new File(_fileName);
	return f.exists(); 
    }


    public void openWriter() throws IOException{
		
	_out = new BufferedWriter(new FileWriter(_fileName));
		
    }
	
    public void appendWriter() throws IOException{
		
	BufferedWriter out = new BufferedWriter(new FileWriter(_fileName, true));
    }
	
    /**
     * Enable you to write a String in a File
     * @param s the string you want to write into the file
     */
    public void write(String s) throws IOException{
	_out.write(s);
    }
	
    /**
     * Close the inputstream associated with the file
     */
    public void close() throws IOException{
	_out.close();
    }
	
    /**
     * Close the inputstream associated with the file
     */
    public void flush() throws IOException{
	_out.flush();
    }
	
    public static void main(String[] args) {
	XMLWriter a = new XMLWriter("Coucou.txt");
	try {
	    a.openWriter();
	    System.out.println("qsdqsdqsdqd\n");
	    a.write("Bonjour");
	    a.write("Bonjour2\n");
	    a.write("Hello3\n");
	    a.write("HastaLuego\n");
	    a.close();
	} catch (IOException e) {
	    //	TODO Auto-generated catch block
	    e.printStackTrace();
	}
	System.out.println("HastaLuego\n");
    }
	
}
